package com.rsstuan.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rsstuan.service.ImageService;

@SuppressWarnings("serial")
public class ImageServlet extends HttpServlet {
	
	private static ImageService imageService = ImageService.getInstance();
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String idStr = request.getParameter("id");
		if (idStr != null) {
			Long itemId = Long.parseLong(idStr);
			byte[] imageData = imageService.getImage(itemId);
			if (imageData != null) {
				response.setContentType("image/jpeg");
				response.getOutputStream().write(imageData);
				response.getOutputStream().flush();
			}
		}
	}
}
